package com.fr.report;

import com.fr.base.FRFont;
import com.fr.base.Style;
import com.fr.base.background.ColorBackground;
import com.fr.base.xml.XMLableReader;
import java.awt.Color;

public class EditResultWorkSheet extends RWorkSheet
{
  protected CellElement createDefaultCellElementCase()
  {
    return new EditCellELement();
  }

  public static class EditCellELement extends DefaultCellElement
  {
    private static final int B = 2;
    private static final int I = 4;
    private static final int U = 8;
    private static final int ST = 16;
    private static final int BTOP = 2;
    private static final int BRIGHT = 4;
    private static final int BBOTTOM = 8;
    private static final int BLEFT = 16;
    private boolean valueDirty = false;
    private String fontName = null;
    private int fontSize = -1;
    private Color fontColor = null;
    private int fontStyle = -1;
    private int borderStyle = -1;
    private Color backgroundColor = null;
    private int horizontal_alignment = -1;
    private int vertical_alignment = -1;

    public void readXML(XMLableReader paramXMLableReader)
    {
      super.readXML(paramXMLableReader);
      if (paramXMLableReader.isAttr())
      {
        String str;
        int i;
        if ((str = paramXMLableReader.getAttr("vd")) != null)
          this.valueDirty = true;
        if ((str = paramXMLableReader.getAttr("ff")) != null)
          this.fontName = str;
        if ((str = paramXMLableReader.getAttr("fs")) != null)
          this.fontSize = Integer.parseInt(str);
        if ((str = paramXMLableReader.getAttr("fc")) != null)
          this.fontColor = new Color(Integer.parseInt(str.substring(1), 16));
        if ((str = paramXMLableReader.getAttr("ft")) != null)
          this.fontStyle = Integer.parseInt(str);
        if ((str = paramXMLableReader.getAttr("br")) != null)
          this.borderStyle = Integer.parseInt(str);
        if ((str = paramXMLableReader.getAttr("bg")) != null)
          this.backgroundColor = new Color(Integer.parseInt(str.substring(1), 16));
        if ((str = paramXMLableReader.getAttr("ta")) != null)
        {
          i = Integer.parseInt(str);
          if (i == 0)
            this.horizontal_alignment = 2;
          else if (i == 1)
            this.horizontal_alignment = 0;
          else
            this.horizontal_alignment = 4;
        }
        if ((str = paramXMLableReader.getAttr("va")) != null)
        {
          i = Integer.parseInt(str);
          if (i == 0)
            this.vertical_alignment = 1;
          else if (i == 1)
            this.vertical_alignment = 0;
          else
            this.vertical_alignment = 3;
        }
      }
    }

    public void checkDirtyValueAndStyle(CellElement paramCellElement, Report paramReport)
    {
      int i;
      int j;
      if (paramReport == null)
        return;
      if (paramCellElement == null)
      {
        paramCellElement = new DefaultCellElement(getColumn(), getRow(), getColumnSpan(), getRowSpan(), getValue());
        paramReport.addCellElement(paramCellElement, false);
      }
      else if (this.valueDirty)
      {
        paramCellElement.setValue(getValue());
      }
      Style localStyle = paramCellElement.getStyle();
      if (localStyle == null)
        paramCellElement.setStyle(Style.DEFAULT_STYLE);
      FRFont localFRFont1 = localStyle.getFRFont();
      FRFont localFRFont2 = localFRFont1;
      if (localFRFont1 == null)
        localFRFont2 = FRFont.getInstance();
      if (this.fontName != null)
        localFRFont2 = localFRFont2.applyName(this.fontName);
      if (this.fontSize > 0)
        localFRFont2 = localFRFont2.applySize(this.fontSize);
      if (this.fontColor != null)
        localFRFont2 = localFRFont2.applyForeground(this.fontColor);
      if (this.fontStyle > 0)
      {
        i = 0;
        if ((this.fontStyle & 0x2) != 0)
          ++i;
        if ((this.fontStyle & 0x4) != 0)
          i += 2;
        if (i != localFRFont2.getStyle())
          localFRFont2 = localFRFont2.applyStyle(i);
        i = ((this.fontStyle & 0x8) != 0) ? 1 : 0;
        if (i != localFRFont2.getUnderline())
          localFRFont2 = localFRFont2.applyUnderline(i);
        j = ((this.fontStyle & 0x10) != 0) ? 1 : 0;
        if (j != localFRFont2.isStrikethrough())
          localFRFont2 = localFRFont2.applyStrikethrough(j);
      }
      if (localFRFont2 != localFRFont1)
        localStyle = localStyle.deriveFRFont(localFRFont2);
      if (this.backgroundColor != null)
        localStyle = localStyle.deriveBackground(ColorBackground.getInstance(this.backgroundColor));
      if (this.borderStyle > 0)
      {
        i = ((this.borderStyle & 0x2) != 0) ? 1 : 0;
        j = ((this.borderStyle & 0x4) != 0) ? 1 : 0;
        int k = ((this.borderStyle & 0x8) != 0) ? 1 : 0;
        int l = ((this.borderStyle & 0x10) != 0) ? 1 : 0;
        localStyle = localStyle.deriveBorder(i, Color.black, k, Color.black, l, Color.black, j, Color.black);
      }
      if ((this.horizontal_alignment >= 0) && (this.horizontal_alignment != localStyle.getHorizontalAlignment()))
        localStyle = localStyle.deriveHorizontalAlignment(this.horizontal_alignment);
      if ((this.vertical_alignment >= 0) && (this.vertical_alignment != localStyle.getVerticalAlignment()))
        localStyle = localStyle.deriveVerticalAlignment(this.vertical_alignment);
      paramCellElement.setStyle(localStyle);
    }
  }
}